/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>退货退款管理</h3>
        <h5>商品订单退货申请及审核处理</h5>
      </div>
      <ul class="tab-base nc-row">
        <router-link
          :to="{name:'returned'}"
          :active-class="returnGoodsQuery.status == 3 ? 'current' : ''"
        >
          <li @click="returnGoodsQuery.status = 3;currentPage = 1;getList()">
            <a>
              <span>待处理</span>
            </a>
          </li>
        </router-link>
        <router-link
          :to="{name:'returned'}"
          :active-class="returnGoodsQuery.status == null ? 'current' : ''"
        >
          <li @click="returnGoodsQuery.status = null;currentPage = 1;getList()">
            <a>
              <span>所有记录</span>
            </a>
          </li>
        </router-link>
      </ul>
    </div>
    <div
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>买家提交申请，商家同意并经平台确认后，退款金额以预存款的形式返还给买家（账户余额）（支付宝支付或者微信用户微信支付支持原路退回）。</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>

    <div class="mDiv">
      <div class="ftitle">
        <h3>待处理的线上实物交易订单退货列表</h3>
        <h5>(共 {{page.total}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="申请日期起始"
          end-placeholder="申请日期截止"
          :picker-options="pickerOptions"
        ></el-date-picker>
        <el-select v-model="searchType" size="small" clearable>
          <el-option
            v-for="item in searchTypeArr"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-input
          v-if="searchType > 0"
          v-model="searchKey"
          size="small"
          placeholder="搜索相关数据"
          clearable
          style="width: 150px"
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage=1;search()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox">
      <el-table :data="page.records" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="买家会员id:">
                <span>{{ props.row.user_id}}</span>
              </el-form-item>
              <el-form-item label="买家会员名:" v-if="props.row.user">
                <span>{{ props.row.user.nickname }}</span>
              </el-form-item>
              <el-form-item label="申请图片:" v-if="props.row.imgs_url">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="props.row.imgs_url[0]"
                  :preview-src-list="props.row.imgs_url"
                ></el-image>
              </el-form-item>
              <el-form-item label="申请原因:">
                <span>{{ props.row.reason }}</span>
              </el-form-item>
              <el-form-item label="退货数量:">
                <span>{{ props.row.goods_num }}</span>
              </el-form-item>
              <el-form-item v-if="props.row.checktime > 0" label="商家审核时间:">
                <span>{{ props.row.check_time_format }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="订单编号" prop="order_sn" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="商品id" prop="goods_id" width="100"></el-table-column>
        <el-table-column label="商品名称" prop="order_goods.goods_name" width="500"></el-table-column>
        <el-table-column label="商家" prop="store.store_name" width="180"></el-table-column>
        <el-table-column label="申请时间" prop="add_time_format" width="200"></el-table-column>
        <el-table-column label="状态" prop="status_desc" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <!-- <router-link :to="{path:'/index/order/returned_detail/'+scope.row.rec_id}"> -->

              <!-- <router-link :to="{name:'returned_detail',params:{rec_id:scope.row.rec_id, endTime:scope.row.end_time}}"> -->
              <el-button
                size="small"
                icon="el-icon-s-order"
                @click="returnedDetail(scope.row.id)"
                v-if="scope.row.status != 0"
              >查看</el-button>
              <el-button
                size="small"
                icon="el-icon-set-up"
                @click="returnedDetail(scope.row.id)"
                v-else-if="scope.row.status == 0"
              >处理</el-button>
              <!-- </router-link> -->
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getReturnGoodsPage } from "@/utils/api";
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      dateRange: "",
      page: {
        total: 0
      },
      currentPage: this.$route.params.currentPage || 1,
      pageSize: 10,
      returnGoodsQuery: {
        add_time_begin: "",
        add_time_end: "",
        status: this.$route.params.status == null ? null : 3,
        order_sn: ""
      },
      searchTypeArr: [
        {
          value: 1,
          label: "商品名称"
        },
        {
          value: 2,
          label: "店铺名称"
        },
        {
          value: 3,
          label: "订单编号"
        }
      ],
      searchType: "",
      searchKey: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getList();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getList();
    },
    getList() {
      if (this.dateRange != null && this.dateRange.length > 1) {
        this.returnGoodsQuery.add_time_begin = parseInt(
          this.dateRange[0].valueOf() / 1000
        );
        this.returnGoodsQuery.add_time_end = parseInt(
          this.dateRange[1].valueOf() / 1000
        );
      }
      var that = this;
      this.returnGoodsQuery.p = this.currentPage;
      this.returnGoodsQuery.size = that.pageSize;
      this.returnGoodsQuery.types = "0,1";
      getReturnGoodsPage(this.returnGoodsQuery).then(function(res) {
        that.page = res;
      });
    },
    refresh() {
      this.getList.success();
      this.$message("刷新成功！");
    },
    returnedDetail(id) {
      this.$router.push({
        name: "returned_detail",
        params: {
          id: id,
          currentPage: this.currentPage,
          status: this.returnGoodsQuery.status
        }
      });
    },
    search() {
      this.$delete(this.returnGoodsQuery, "goods_name");
      this.$delete(this.returnGoodsQuery, "store_name");
      this.$delete(this.returnGoodsQuery, "order_sn");
      if (this.searchType == 1) {
        this.returnGoodsQuery.goods_name = this.searchKey;
      } else if (this.searchType == 2) {
        this.returnGoodsQuery.store_name = this.searchKey;
      } else if (this.searchType == 3) {
        this.returnGoodsQuery.order_sn = this.searchKey;
      }
      this.currentPage = 1;
      this.getList();
    }
  }
};
</script>

<style scoped>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-left: 4%;
  margin-bottom: 0;
  width: 40%;
}
</style>
